<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/admin/include/init_admin.jsp" %>
<%@ page import="com.welfare.admin.call.*" %>
<%

	HashList code007	= CommonUtil.getCodeList("007", "전체");	//행정동
	HashList code305	= CommonUtil.getCodeList("305");	//분류1
	HashList code306	= CommonUtil.getCodeList("306");	//분류2
	
	//대분류별 소분류 갯수를 구한다.
	for (int i = 0; i < code305.size(); i++) {
		String counsel_kind = StringUtil.nvl(code305.get("code",i));
		int kind2 = 0; 
		for (int j = 0; j < code306.size(); j++) {
			if (counsel_kind.equals(code306.get("code_desc",j))) {
				kind2++;
			}
		}
		code305.put("code_num1", i, String.valueOf(kind2));
	}
	
	
	HashList code310	= CommonUtil.getCodeList("310");	//통계구분
	
	HashBox box = new HashBox(request);

	String s_from_dt		= StringUtil.nvl(request.getParameter("s_from_dt"), TODAY.substring(0,6)+"01");
	String s_to_dt			= StringUtil.nvl(request.getParameter("s_to_dt"), TODAY);
	String s_dong_code		= StringUtil.nvl(request.getParameter("s_dong_code"));
	String s_counsel_kind	= StringUtil.nvl(request.getParameter("s_counsel_kind"), "1");
	String s_group_col		= StringUtil.nvl(request.getParameter("s_group_col"), "counsel_path");


	HashMap infos = new HashMap();
	infos.put("from_dt",		s_from_dt);
	infos.put("to_dt",			s_to_dt);
	infos.put("dong_code",		s_dong_code);
	infos.put("counsel_kind", 	s_counsel_kind);
	infos.put("group_col", 		s_group_col);
	infos.put("code305",		code305);	//대분류
	infos.put("code306",    	code306);	//소분류

	CallDAO dao 	= new CallDAO();
	HashList list 	= dao.selectCounselAnalysis(infos);

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title><%= SYSTEM_NAME %> 관리자</title>
	<%@ include file="/admin/include/cssnjs.jsp"  %>
	<script type="text/javascript">
	$(document).ready(function() {
		$('#s_from_dt').mask('9999.99.99').datepicker();
		$('#s_to_dt').mask('9999.99.99').datepicker();
		$('#s_service_name').focus().select();
		
		/* $('#list').find('tr').hover(
				function () { $(this).addClass("hover"); }
			  , function () { $(this).removeClass("hover"); }
			) */
		$('input[name="s_group_col"], input[name="s_counsel_kind"]').click(function() {
			$('#searchForm').submit();
		});
	});
	
	function fnExcel() {
		$('#searchForm').attr('action', './counselAnalysisExcel.jsp');
		$('#searchForm').submit();
		$('#searchForm').attr('action', './counselAnalysis.jsp');
	}
	
	</script>
</head>
<body>
<div id="wrap">
	<div id="page">
		<div id="contents_nowidth">
			<div class="menu_title">
				<h1>상담통계</h1>
				<p>관리자 > 콜센터 > <b>상담통계</b></p>
			</div>
			<div class="clear line_01"></div>

			<form id="searchForm" method="post" action="./counselAnalysis.jsp">

			<table cellpadding="0" cellspacing="0" class="table_01 mt15">
			<colgroup>
				<col width="100px" />
				<col width="220px" />
				<col width="100px" />
				<col width="200px" />
				<col width="100px" />
				<col  />
			</colgroup>
			<tr>
				<th><p>조회기간</p></th>
				<td>
					<input type="text" name="s_from_dt" id="s_from_dt" value="<%= s_from_dt %>" class="w80 c" maxlength="10"/>
					~ 
					<input type="text" name="s_to_dt" id="s_to_dt" value="<%= s_to_dt %>" class="w80 c" maxlength="10"/>
				</td>
				<th><p>행정동</p></th>
				<td>
					<select name="s_dong_code" class="w100">
					<%= StringUtil.makeOption(code007, s_dong_code) %>
					</select>
				</td>
				<th><p>상담분류</p></th>
				<td class="brx">
					<input type="radio" class="radio" name="s_counsel_kind" id="s_counsel_kind1" value="1" <%=StringUtil.checked("1", s_counsel_kind) %> /><label class="radio" for="s_counsel_kind1">분류1</label>
					<input type="radio" class="radio" name="s_counsel_kind" id="s_counsel_kind2" value="2" <%=StringUtil.checked("2", s_counsel_kind) %> /><label class="radio" for="s_counsel_kind2">분류2</label>
				</td>
			</tr>
			<tr>
				<th><p>통계구분</p></th>
				<td colspan="5" class="brx">
					<%= StringUtil.makeRadio(code310, "s_group_col", s_group_col) %>
				</td>
			</tr>
			</table>

			<div class="mt10 mb10 r">
				<input type="image" class="button" src="../images/btn_search.gif"/>
				<a href="#nohref" onclick="fnExcel()"><img src="../images/btn_excel.gif"/></a>
			</div>

			</form>

		    <table width="100%" cellpadding="0" cellspacing="0" class="table_04">
				<colgroup>
					<col width="100px"/>
					<col width="60px"/>
				</colgroup>
				<thead>
	<%	if ("1".equals(s_counsel_kind)) { %>
	
					<tr> 
						<th><p>구분</p></th>
						<th><p>합계</p></th>
			<%	for (int i = 0; i < code305.size(); i++) { %>
						<th><p><%=code305.get("code_name",i) %></p></th>
			<%	} %>
					</tr>
	
	<%	} else { %>
				
					<tr> 
						<th rowspan="2"><p>구분</p></th>
						<th rowspan="2"><p>합계</p></th>
			<%	for (int i = 0; i < code305.size(); i++) { %>
						<th colspan="<%=code305.get("code_num1",i)%>"><p><%=code305.get("code_name",i) %></p></th>
			<%	} %>
					</tr>
					<tr>
			<%	for (int i = 0; i < code306.size(); i++) { %>
						<th><p><%=code306.get("code_name",i) %></p></th>
			<%	} %>		
					</tr>
					
	<%	} %>
					
				</thead>
				<tbody id="list">
			<%	
				HashList codeList = "1".equals(s_counsel_kind) ? code305 : code306;
				String sumClassName = "";
				for (int i = 0; i < list.size(); i++) { 
					if (i == 0) {
						sumClassName = "";	//"class=\"sum\"";
					} else {
						sumClassName = "";
					}
			%>
					<tr <%= sumClassName %>>
						<td><%= list.get("group_col", i) %></td>
						<td><%= list.getPrice("sum", i) %></td>
			<%		
					for (int idx = 0; idx < codeList.size(); idx++) { %>
						<td><%= list.getPrice("sum_"+codeList.get("code",idx), i) %></td>
			<%		} %>
					</tr>
			<%	} %>
					
				</tbody>
			</table>

		</div>
	</div>
</div>
</body>
</html>
